Utils::FileInProjectFinder Class
class Utils::FileInProjectFinderThe FileInProjectFinder class is a helper class to find the original file in the project directory for a given file URL. More...
| Header: | #include <fileinprojectfinder.h> |
Public Functions
| Utils::FilePaths | findFile(const Utils::FilePath &filePath, bool *success = nullptr) const |
| Utils::FilePaths | findFile(const QUrl &fileUrl, bool *success = nullptr) const |
Detailed Description
Often files are copied in the build and deploy process. findFile() searches for an existing file in the project directory for a given file path.
For example, the following file paths should all be mapped to $PROJECTDIR/qml/app/main.qml:
- C:/app-build-desktop/qml/app/main.qml (shadow build directory)
- /Users/x/app-build-desktop/App.app/Contents/Resources/qml/App/main.qml (folder on macOS)
Member Function Documentation
Utils::FilePaths FileInProjectFinder::findFile(const Utils::FilePath &filePath, bool *success = nullptr) const
Returns the best match for filePath in the project directory.
A resource path, as recognized by FilePath::isResourceFile(), is first looked up in the .qrc files of the project. If that finds nothing, the search continues with the path without the : or qrc prefix.
The function then checks whether the file inside the project directory exists. If not, the leading directory in the path is stripped, and the - now shorter - path is checked for existence, and so on. Second, it tries to locate the file in the sysroot folder specified. Third, it walks the list of project files and searches for a file name match there.
If all fails, the function returns filePath unchanged, including a resource path such as :/qml/main.qml. To indicate that no match was found in the project, success is set to false.
Utils::FilePaths FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success = nullptr) const
Returns the best match for the file URL fileUrl in the project directory.
A qrc URL, or a URL starting with :, is first looked up in the .qrc files of the project. If that finds nothing, the URL is reduced to a file path that is passed on to findFile(const FilePath &, bool *) together with success. A file URL becomes its local file, any other URL its path without the scheme. So if nothing matches, qrc:/qml/main.qml comes back as /qml/main.qml.
This is an overloaded function.